/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.api.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.app.dto.FaceFeatureDto;
import com.yami.shop.bean.model.FaceFeature;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.FaceFeatureService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import cn.hutool.core.bean.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 五官资源接口
 * @author AI Assistant
 */
@RestController
@RequestMapping("/p/faceFeature")
@Tag(name = "五官资源接口")
public class FaceFeatureController {

    @Autowired
    private FaceFeatureService faceFeatureService;

    /**
     * 获取五官资源列表（分页）
     */
    @GetMapping("/page")
    @Operation(summary = "获取五官资源列表" , description = "分页获取五官资源列表")
    @Parameter(name = "featureType", description = "五官类型（1:眼睛, 2:眉毛, 3:鼻子, 4:嘴巴, 5:腮红, 6:发型）", required = false)
    @Parameter(name = "status", description = "状态（0:禁用, 1:启用）", required = false)
    public ServerResponseEntity<IPage<FaceFeatureDto>> page(
            @RequestParam(value = "featureType", required = false) Integer featureType,
            @RequestParam(value = "status", required = false) Integer status,
            PageParam<FaceFeature> page) {

        IPage<FaceFeature> faceFeaturePage = faceFeatureService.pageByFeatureTypeAndStatus(page, featureType, status);
        IPage<FaceFeatureDto> faceFeatureDtoPage = faceFeaturePage.convert(faceFeature -> {
            FaceFeatureDto faceFeatureDto = BeanUtil.copyProperties(faceFeature, FaceFeatureDto.class);
            return faceFeatureDto;
        });

        return ServerResponseEntity.success(faceFeatureDtoPage);
    }

    /**
     * 获取所有五官资源列表
     */
    @GetMapping("/list")
    @Operation(summary = "获取所有五官资源列表" , description = "获取所有五官资源列表")
    @Parameter(name = "featureType", description = "五官类型（1:眼睛, 2:眉毛, 3:鼻子, 4:嘴巴, 5:腮红, 6:发型）", required = false)
    @Parameter(name = "status", description = "状态（0:禁用, 1:启用）", required = false)
    public ServerResponseEntity<List<FaceFeatureDto>> list(
            @RequestParam(value = "featureType", required = false) Integer featureType,
            @RequestParam(value = "status", required = false) Integer status) {

        List<FaceFeature> faceFeatureList = faceFeatureService.listByFeatureTypeAndStatus(featureType, status);
        List<FaceFeatureDto> faceFeatureDtoList = BeanUtil.copyToList(faceFeatureList, FaceFeatureDto.class);

        return ServerResponseEntity.success(faceFeatureDtoList);
    }

    /**
     * 获取五官资源详情
     */
    @GetMapping("/info")
    @Operation(summary = "获取五官资源详情" , description = "根据五官资源ID获取详情")
    @Parameter(name = "featureId", description = "五官资源ID", required = true)
    public ServerResponseEntity<FaceFeatureDto> info(@RequestParam("featureId") Long featureId) {

        FaceFeature faceFeature = faceFeatureService.getById(featureId);
        if (faceFeature == null) {
            return ServerResponseEntity.success();
        }

        FaceFeatureDto faceFeatureDto = BeanUtil.copyProperties(faceFeature, FaceFeatureDto.class);
        return ServerResponseEntity.success(faceFeatureDto);
    }

    /**
     * 根据类型获取启用的五官资源列表
     */
    @GetMapping("/listByType")
    @Operation(summary = "根据类型获取启用的五官资源列表" , description = "根据五官类型获取启用的资源列表")
    @Parameter(name = "featureType", description = "五官类型（1:眼睛, 2:眉毛, 3:鼻子, 4:嘴巴, 5:腮红, 6:发型）", required = true)
    public ServerResponseEntity<List<FaceFeatureDto>> listByType(@RequestParam("featureType") Integer featureType) {

        List<FaceFeature> faceFeatureList = faceFeatureService.listByFeatureTypeAndStatus(featureType, 1);
        List<FaceFeatureDto> faceFeatureDtoList = BeanUtil.copyToList(faceFeatureList, FaceFeatureDto.class);

        return ServerResponseEntity.success(faceFeatureDtoList);
    }

    /**
     * 根据多个类型获取启用的五官资源列表
     */
    @GetMapping("/listByTypes")
    @Operation(summary = "根据多个类型获取启用的五官资源列表" , description = "根据多个五官类型获取启用的资源列表")
    @Parameter(name = "featureTypes", description = "五官类型列表（1:眼睛, 2:眉毛, 3:鼻子, 4:嘴巴, 5:腮红, 6:发型）", required = true)
    public ServerResponseEntity<List<FaceFeatureDto>> listByTypes(@RequestParam("featureTypes") List<Integer> featureTypes) {

        List<FaceFeature> faceFeatureList = faceFeatureService.listByFeatureTypesAndStatus(featureTypes, 1);
        List<FaceFeatureDto> faceFeatureDtoList = BeanUtil.copyToList(faceFeatureList, FaceFeatureDto.class);

        return ServerResponseEntity.success(faceFeatureDtoList);
    }
}
